import request from './request'

export interface Account {
  id?: number
  username: string
  password?: string
  email?: string
  phone?: string
  role: 'admin' | 'beautician' | 'receptionist' | 'manager'
  status: 0 | 1
  real_name?: string
  createdAt?: string
  updatedAt?: string
}

export interface AccountListParams {
  page?: number
  pageSize?: number
  username?: string
  real_name?: string
  role?: string
  status?: number
}

export interface AccountListResponse {
  list: Account[]
  total: number
  page: number
  pageSize: number
}

// 获取账户列表
export const getAccounts = (params: AccountListParams) => {
  return request({
    url: '/user/page',
    method: 'post',
    data: {
      ...params
    }
  })
}

// 创建账户
export const createAccount = (data: Omit<Account, 'id'>) => {
  return request({
    url: '/user/add',
    method: 'post',
    data
  })
}

// 更新账户
export const updateAccount = (id: number, data: Partial<Account>) => {
  return request({
    url: `/user/update`,
    method: 'post',
    data: {
      id,
      ...data
    }
  })
}

// 删除账户
export const deleteAccount = (id: number) => {
  return request({
    url: `/user/${id}`,
    method: 'delete'
  })
}

// 重置密码
export const resetPassword = (id: number, newPassword: string) => {
  return request({
    url: `/user/resetPassword`,
    method: 'post',
    data: {
      id,
      newPassword
    }
  })
}